/*
 * @Description: 购物车状态模块
 * @Author: pdx
 * @Date: 2020-10-8 18:40:41
 * @LastEditors: pdx
 * @LastEditTime: 2020-03-07 20:38:55
 */
export default {
  state: {
    shoppingCart: [],  //购物车信息
    shoppingCartNum: 0,  //购物车数量
    checkGameIds: [],  //购物车中商品id
  },
  getters: {
    getShoppingCart (state) {
      // 获取购物车状态
      return state.shoppingCart;
    },
    getNum (state) {
      return state.shoppingCartNum;
    },
    getCheckGameIds(state) {
      return state.checkGameIds;
    }
  },
  mutations: {
    setShoppingCart (state, data) {
      // 设置购物车状态
      state.shoppingCart = data;
    },
    unshiftShoppingCart (state, data) {
      // 添加购物车
      // 用于在商品详情页点击添加购物车,后台添加成功后，更新vuex状态
      state.shoppingCart.unshift(data);
    },
    setShoppingCartNum(state, num) {
      state.shoppingCartNum = num
    },

    setCheckGameIds(state, data) {
      state.checkGameIds = data
    }
  },
  actions: {
    setShoppingCartNum({commit}, num) {
      commit('setShoppingCartNum', num)
    },
    setShoppingCart ({ commit }, data) {
      commit('setShoppingCart', data);
    },
    unshiftShoppingCart ({ commit }, data) {
      commit('unshiftShoppingCart', data);
    },
    setCheckGameIds ({ commit }, data) {
      commit('setCheckGameIds', data);
    }
  }
}